package chatGUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;


import java.util.Observable;
import java.util.Observer;

import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JTextPane;

import chatController.ChatController;
import chatModel.ChatModel;
import chatModel.Conversation;
import chatModel.User;
import chatModel.ChatModel.Val;
/* 
 * @author Yahya-Albaba
*/


@SuppressWarnings("unused")

public class ChatGui implements Observer {
	/**
	 * @param  conWin this parameter is the instance of the connection window that we use   
	 * @param  chatWin this parameter is the instance of the chat window that we use 
	 * @param  cc this parameter is the instance of the chat controller that we use in this chat system
	 * @param  cc this parameter is the instance of the chat Model that we use in this chat system
	*/
	
	private  ConnectionWindow conWin;
	private  ChatWindow chatwin;//Meow!
	protected ChatController cc;
	protected ChatModel cm;

	public ChatGui(ChatModel cm){
		this.cm=cm;
		conWin = new ConnectionWindow(this);
	}
	

	
	public void setCc(ChatController cc) {
		this.cc = cc;
	}

	/**
	 *This method allows us to connect, we use the chat controller to do get connected
	*/
	public void connect(String username) {
		cc.performConnect(username);
	}

	
	public void close(){
		System.exit(0);
	}	

	/**
	 *This method allows us to add a tab in the conversation list
	*/
	public void addTab(Conversation c) {
        chatwin.openConversation(c);
    }


	@Override
	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub
		if(arg1.equals(Val.CONNEXIONSTATE)){
			this.chatwin = new ChatWindow(this);

		}else  {
            String username=(String) arg1;
			chatwin.updateUsersList(username);
		}
		
	}	
	


	public ChatWindow getChatwindow() {
		return chatwin;
	}


}